<?php
require ("../database/categories.php");
?>
<?php 
  $id=$_GET['id'];
  $cate1=new categories();
  $data=$cate1->showOne($id);
  $error_name="";
  $error_infor="";
  $error_status="";
  $cate=new categories();
  if(isset($_POST['ok'])){   
      if($_POST['name']==""){
          $error_name="Khong duoc de trong !";
         
      }else {
         if(trim($_POST['name'])==$data['cate_name']){
            if($cate->update($id,trim($_POST['name']), trim($_POST['infor']),trim( $_POST['status']))){
             echo'<span style="color:red;">Ban da cap nhat thanh cong </span></br>';
         }  else {
             echo '<span style="color:red;">Cap nhat du lieu that bai !</span></br>';
         }
         }else{
             if($cate->isExistName(trim($_POST['name'])))$error_name="Da ton tai!";
         else {
         if($cate->update($id,trim($_POST['name']), trim($_POST['infor']),trim( $_POST['status']))){
             echo'<span style="color:red;">Ban da cap nhat thanh cong </span></br>';
         }  else {
             echo '<span style="color:red;">Cap nhat du lieu that bai !</span></br>';
         }
            
         }
      }
  }
  }
?>
<h1>Trinh sua thong tin san pham</h1>
<form method="post" action="">
<table>
    <tr>
        <td>Ten loai san pham :</td>
        <td><input type="text"size="30" name="name" value="<?php echo $data['cate_name'];?>"> <span style="color: red">*<?php echo $error_name;?></span></td>
    </tr>
    <tr>
        <td>Thong tin: </td>
        <td><textarea rows="10" cols="30" name="infor"><?php echo $data['cate_infor'];?></textarea> <span><?php echo $error_infor;?></span></td>
    </tr>
    <tr>
        <td>Trang thai:</td>
        <td><input type="text" size="50" name="status" value="<?php echo $data['cate_status'];?>"> <span><?php echo $error_status;?></span></td>
    </tr>
    <tr>
        <td></td>
        <td><input type="submit" name="ok" value="Cap nhat"></td>
    </tr>
</table>
</form>